package com.himiotech.core.project.web;

import com.himiotech.core.framework.config.shiro.service.RegisterService;
import com.himiotech.core.project.model.entity.user.User;
import com.himiotech.core.project.service.IConfigService;
import com.himiotech.core.project.web.base.HimioBaseController;
import com.himiotech.core.project.web.base.model.HimioResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 注册验证
 *
 * @author ruoyi
 * @author wuwenbin
 */
@Controller
public class RegisterController extends HimioBaseController {
    @Autowired
    private RegisterService registerService;

    @Autowired
    private IConfigService configService;

    @GetMapping("/register")
    public String register() {
        return "reg";
    }

    @PostMapping("/register")
    @ResponseBody
    public HimioResult ajaxRegister(User user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return writeJsonErr("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? writeJsonOk() : writeJsonErr(msg);
    }
}
